from django_filters import FilterSet, filters
from studentweb.models import Faculty, Major, Student


class FacultyFilter(FilterSet):
    """
    Faculty的Filter类
    Args:
        FilterSet (_type_): _description_
    """
    name = filters.CharFilter(field_name='name', lookup_expr='icontains')

    class Meta:
        model = Faculty
        fields = ('name',)


class MajorFilter(FilterSet):
    """
    Major的Filter类
    Args:
        FilterSet (_type_): _description_
    """
    name = filters.CharFilter(field_name='name', lookup_expr='icontains')
    faculty = filters.CharFilter(field_name='faculty', lookup_expr='icontains')

    class Meta:
        model = Major
        fields = ('name', 'faculty')


class StudentFilter(FilterSet):
    """
    Student的Filter类
    Args:
        FilterSet (_type_): _description_
    """
    sno = filters.CharFilter(field_name='sno', lookup_expr='icontains')
    name = filters.CharFilter(field_name='name', lookup_expr='icontains')
    mobile = filters.CharFilter(field_name='mobile', lookup_expr='icontains')

    class Meta:
        model = Student
        fields = ('sno', 'name', 'mobile')
